//
//  SpringViewController.swift
//  swiftAnimation
//
//  Created by zhouLiHuan on 2017/2/16.
//  Copyright © 2017年 zhouLiHuan. All rights reserved.
//

import UIKit

class SpringViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white;
        let label = UILabel(frame:CGRect(x:10,y:200,width:50,height:30));
        label.backgroundColor = UIColor.red;
        view.addSubview(label);
        
        let spring = CASpringAnimation(keyPath: "position.x");
        spring.damping = 5; //阻尼系数
        spring.stiffness = 100; //刚度系数 越大变形越大 运动越快
        spring.mass = 1; //质量 影响图层运动时的的弹簧惯性 质量越大 惯性越大 为10的时候 变成动画
        spring.initialVelocity = 0;//初始速度
        spring.fromValue = label.layer.position.x;
        spring.toValue = label.layer.position.x + 100;
        spring.autoreverses = true;
        spring.repeatCount = Float.infinity;
        spring.duration = spring.settlingDuration;
        label.layer.add(spring, forKey: spring.keyPath);
        
        
    }


}
